import CommonBaseSchema from '#common/base_schema'

export default class extends CommonBaseSchema {
  protected tableName = 'payment_details'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments()
      table.integer('fk_shop_id').notNullable().unsigned().references('shops.id').comment('店铺ID')

      table
        .integer('fk_sales_order_id')
        .notNullable()
        .unsigned()
        .references('sales_orders.id')
        .comment('销售单ID')

      table.integer('fk_member_id').unsigned().references('members.id').comment('会员ID')

      table
        .integer('fk_member_rights_id')
        .unsigned()
        .references('card_rights.id')
        .comment('会员权益ID')

      table
        .integer('fk_payment_method')
        .notNullable()
        .unsigned()
        .references('dicts.id')
        .comment('支付方式ID')

      table.string('bill_no', 60).comment('单号')
      table.tinyint('bill_uid').unsigned().defaultTo(1).comment('单据UID')
      table.dateTime('bill_date').comment('单据日期')
      table.string('bill_type', 10).comment('单据类型')
      table.integer('normal_price').unsigned().defaultTo(0).comment('正常价格')
      table.tinyint('discount').unsigned().defaultTo(10).comment('折扣')
      table.integer('actual_price').unsigned().defaultTo(0).comment('实际价格')
      table.integer('actual_pay_price').unsigned().defaultTo(0).comment('实际支付价格')
      table.string('memo', 255).defaultTo('').comment('备注')

      this.defineCommonColumns(table)
      table.comment('支付清单表')
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
